import 'package:data/repository/banner/banner_repository.dart';
import 'package:data/repository/home_articles/home_articles_repository.dart';
import 'package:data/repository/home_articles/home_articles_repository_impl.dart';
import 'package:data/repository/projects/projects_repository.dart';
import 'package:dio/dio.dart';
import 'package:domain/usecases/banner_use_case.dart';
import 'package:domain/usecases/home_article_use_case.dart';
import 'package:domain/usecases/projects_use_case.dart';
import 'package:feature_main/feature_config.dart';
import 'package:feature_projects/feature_config.dart';
import 'package:get/get.dart';
import 'package:get_it/get_it.dart';
import 'package:wanandroid_client/route/route_names.dart';

void setupDependencies() {
  final getIt = GetIt.instance;
  _setupDomainDependencies(getIt);
  _setupUIDependencies(getIt);
}

void _setupDomainDependencies(GetIt getIt) {
  getIt.registerLazySingleton<Dio>(() => Dio());
  getIt.registerLazySingleton<HomeArticlesRepository>(
    () => HomeArticlesRepositoryImpl(dio: getIt<Dio>()),
  );
  getIt.registerLazySingleton<BannerRepository>(
    () => BannerRepositoryImpl(dio: getIt<Dio>()),
  );
  getIt.registerLazySingleton<ProjectsRepository>(
    () => ProjectsRepositoryImpl(dio: getIt<Dio>()),
  );
  getIt.registerLazySingleton<HomeArticleUseCase>(
    () => HomeArticleUseCaseImpl(repository: getIt<HomeArticlesRepository>()),
  );
  getIt.registerLazySingleton<BannerUseCase>(
    () => BannerUseCaseImpl(repo: getIt.get()),
  );
  getIt.registerLazySingleton<ProjectsUseCase>(
    () => ProjectsUseCaseImpl(repository: getIt.get()),
  );
}

void _setupUIDependencies(GetIt getIt) {
  getIt.registerLazySingleton<MainFeatureConfig>(
    () => MainFeatureConfig(
      navigateToWebview: (String title, String url) async {
        await Get.toNamed(
          RouteNames.webviewPage,
          parameters: {"title": title, "url": url},
        );
      },
    ),
  );
  getIt.registerLazySingleton<ProjectsFeatureConfig>(
    () => ProjectsFeatureConfig(
      navigateToWebview: (String title, String url) async {
        await Get.toNamed(
          RouteNames.webviewPage,
          parameters: {"title": title, "url": url},
        );
      },
    ),
  );
}
